import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['font.sans-serif'] = ['SimHei']

# 数据
companies = ['三棵树', '亚士创能']
revenue_growth = [10.03, 0.09]  # 营业收入同比增长率
net_profit_decline = [47.33, 43.09]  # 净利润同比下降率

# 三棵树产品营收数据
sancks_products = ['家装墙面漆', '工程墙面漆']
sancks_revenue = [26.317, 46.757]  # 单位：亿元
sancks_growth = [2.58, 9.52]  # 同比增长率

# 亚士创能产品营收数据
yashu_products = ['功能型建筑涂料']
yashu_revenue = [20.958]  # 单位：亿元
yashu_growth = [-4.01]  # 同比增长率

# 设置颜色
colors = ['skyblue', 'lightgreen', 'lightcoral', 'sandybrown']

# 创建图表
fig, ax = plt.subplots(figsize=(10, 6))

# 营业收入和净利润同比增长条形图
bar_width = 0.35
index = np.arange(len(companies))
bar1 = ax.bar(index, revenue_growth, bar_width, color=colors[0], label='Revenue Growth')
bar2 = ax.bar(index + bar_width, net_profit_decline, bar_width, color=colors[1], label='Net Profit Decline')

# 三棵树产品营收条形图
bar3 = ax.bar(0, sancks_revenue[0], bar_width, bottom=sancks_revenue[1], color=colors[2], label='三棵树产品营收')

# 亚士创能产品营收条形图
bar4 = ax.bar(1, yashu_revenue[0], bar_width, color=colors[3], label='亚士创能产品营收')

# 设置标题和轴标签
plt.title('Revenue and Net Profit Growth Comparison')
plt.xlabel('Company')
plt.ylabel('Percentage / Billion Yuan')

# 设置X轴刻度标签
ax.set_xticks(index + bar_width / 2)
ax.set_xticklabels(companies)

# 在条形图上显示数据
def autolabel(rects):
    for rect in rects:
        height = rect.get_height()
        plt.text(rect.get_x() + rect.get_width() / 2., 1.05 * height, '%d%%' % int(height),
                 ha='center', va='bottom')

autolabel(bar1)
autolabel(bar2)

# 显示产品营收数据
plt.text(0 + bar_width / 2, sancks_revenue[0] + sancks_revenue[1] / 2, f'{sancks_revenue[0]}亿', ha='center', va='center')
plt.text(0 + bar_width / 2, sancks_revenue[1] / 2, f'{sancks_revenue[1]}亿', ha='center', va='center')
plt.text(1 + bar_width / 2, yashu_revenue[0] / 2, f'{yashu_revenue[0]}亿', ha='center', va='center')

# 图例
ax.legend()

# 显示图形
plt.show()